package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ArticleHomeService;
import com.heima.common.exception.CustomException;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-09-17 11:34
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleFeignImpl {

    @Autowired
    private ArticleHomeService articleHomeService;

    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto articleDto){

        //参数校验
        if(StringUtils.isBlank(articleDto.getTitle())){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }

        Long id = articleHomeService.save(articleDto);
        return ResponseResult.okResult(id);
    }

}
